package logic

import (
	"context"
	"errors"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/renrenzu"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *renrenzu.OrderListRequest) (*renrenzu.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Orders{}
	list, err := o.OrderList()
	if err != nil {
		logx.Error("订单信息获取失败")
		return nil, errors.New("订单信息获取失败")
	}
	lists := []*renrenzu.OrderList{}
	for _, v := range list {
		lists = append(lists, &renrenzu.OrderList{
			UserID:      int64(v.UserID),
			GoodsID:     int64(v.GoodsID),
			OrderTitle:  v.OrderTitle,
			OrderCover:  v.OrderCover,
			OrderAmount: float32(v.OrderAmount),
			OrderStock:  int64(v.OrderStock),
			OrderState:  int64(v.OrderState),
			OrderSn:     v.OrderSn,
		})
	}
	return &renrenzu.OrderListResponse{List: lists}, nil
}
